#include "mongoclient.h"

int main(){
    DBClientConnection client;
    client.connect("127.0.0.1");
    printf("size: %llu \n", client.count("test.user", BSON("name"<<"bushaofeng")));
    client.remove("test.user", BSON("name"<<"bushaofeng"));
    client.insert("test.user", BSON("name"<<"bushaofeng"<<"passwd"<<"abc123"));
    client.insert("test.user", BSON("name"<<"tangziqi"<<"passwd"<<"abc1234"));
    client.insert("test.user", BSON("name"<<"bushaofeng"<<"passwd"<<"abc5678"<<"age"<<18));

    //char* str = "{name : \"bushaofeng\", passwd : \"5678\", age : 18}";
    const char* str = "{name: \"bushaofeng\", passwd: \"9999\", age: 18 }";
    try{
    BSONObj obj = fromjson(str);
    client.insert("test.user", obj);
    }catch(MsgAssertionException){
        cout<<"parse err"<<endl;
    }

    printf("size: %llu \n", client.count("test.user", BSON("name"<<"bushaofeng")));
    /*
    BSONArrayBuilder builder;
    vector<BSONObj> v = client.query("test.user", BSON("name"<<"bushaofeng"));
    for(int i=0;i<v.size();i++){
        //cout<<v[i].toString()<<endl;
        //cout<<v[i].jsonString()<<"\t"<<v[i].jsonString().length()<<endl<<endl;
        builder.append(v[i].removeField("_id"));
    }
    cout<<builder.obj().jsonString()<<endl;
    */
    cout<<client.query("test.user", BSON("name"<<"bushaofeng")).jsonString()<<endl;
    
    return 0;
}
